﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using MSjogren.Samples.ShellLink;
using System.IO;

namespace SynoManager.Utils
{
    public static class StartWithWindows
    {
        private const string linkName = "SynoManager.lnk";

        public static bool IsInStartupFolder()
        {
            string startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            string linkPath = Path.Combine(startupFolder, linkName);
            return File.Exists(linkPath);
        }

        public static void AddToStartupFolder()
        {
            string path = Assembly.GetEntryAssembly().Location;

            string startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            string linkPath = Path.Combine(startupFolder, linkName);

            ShellShortcut link = new ShellShortcut(linkPath);
            link.Path = path;
            link.Description = "Start SynoManager";
            link.Save();
        }

        public static void RemoveFromStartupFolder()
        {
            string startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            string linkPath = Path.Combine(startupFolder, linkName);
            File.Delete(linkPath);
        }
    }
}
